package com.liruo.learn.spring.security.controller;

import com.liruo.learn.spring.security.model.VerificationCodeReq;
import com.liruo.learn.spring.security.resphandler.BaseResp;
import com.liruo.learn.spring.security.resphandler.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:liruo
 * @Date:2023-05-26-19:44:06
 * @Desc
 */
@Slf4j
@RestController
@RequestMapping("/api")
public class VerificationCodeController {
    @PostMapping("/verificationCode")
    public BaseResp<Boolean> verificationCode(@RequestBody VerificationCodeReq verificationCode) {
        log.info("verificationCode={}", verificationCode);
        final String account = verificationCode.getAccount();
        switch (verificationCode.getAccountType()) {
            case email:
                if (!"2372221537@qq.com".equals(account)) {
                    throw new BusinessException("email must 2372221537@qq.com");
                }
                break;
            case phone:
                if (!"12345678901".equals(account)) {
                    throw new BusinessException("phone must 12345678901");
                }
                break;
        }
        return BaseResp.ok(true);
    }
}
